home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p2.arc / NODEPROC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  7.4 KB  |  181 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------            KopyRong (K) 1987.  ALL RIGHTS REVERSED.       */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*               This module was written by Vince Perriello                 */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*                 BinkleyTerm Nodelist processing module                   */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*   This  software  package is being distributed WITH FULL SOURCE CODE     */
  18. /*   with the  following  conditions:    1)  If  anything awful happens     */
  19. /*   because  you  use    it   (or  don't  use  it),  you  accept  full     */
  20. /*   responsibility;  2) you  don't start making tons of voice calls to     */
  21. /*   the authors to complain or  make  suggestions  about enhancements,     */
  22. /*   useful or otherwise;  3) you  do not reuse this code in commercial     */
  23. /*   products without specific permission to do so  from  the  authors;     */
  24. /*   4) If you find any problems you send  fixes  to  the  authors  for     */
  25. /*   inclusion  in  updates;    5) You find some way  to  express  your     */
  26. /*   appreciation  for  this  method of distribution, either by writing     */
  27. /*   code or  application  notes,  or  just sending along a "Thank You"     */
  28. /*   message.                                                               */
  29. /*                                                                          */
  30. /*   There is  copyrighted  code  in  this product.  We either wrote it     */
  31. /*   ourselves or got  permission  to use it.  Please don't force us to     */
  32. /*   pay a lawyer --  have some respect for our motives and don't abuse     */
  33. /*   this "license".                                                        */
  34. /*                                                                          */
  35. /*                                                                          */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. #include <sys\types.h>
  39. #include <sys\stat.h>
  40. #include <stdio.h>
  41. #include <fcntl.h>
  42. #include <signal.h>
  43. #include <ctype.h>
  44. #include <conio.h>
  45. #include "com.h"
  46. #include "xfer.h"
  47. #include "keybd.h"
  48.  
  49. extern struct pointers ctl;            /* where all the strings is  */
  50. int autobaud = 0;    /* Use highest baud rate when calling out */
  51. struct _node nodedes;                /* desc. of node             */
  52. static struct _ndi *node_index = NULL;        /* pointer to node array     */
  53. static int idx_size = 0;            /* number of entries in it   */
  54.  
  55. /*---------------------------------------------------------------------------*/
  56. /* NODEPROC                                                                  */
  57. /* Find nodelist entry and set baud to nodelist baud for dialing out         */
  58. /*---------------------------------------------------------------------------*/
  59.  
  60. nodeproc(nodeaddr)
  61. char *nodeaddr;
  62. {
  63. int opusnet,opusnode;                /* net and node              */
  64. char *c,*skip_blanks();
  65.  
  66. c = skip_blanks(nodeaddr);            /* get rid of the blanks     */
  67. if (sscanf(c,"%d/%d",&opusnet,&opusnode) != 2)
  68.     {
  69.     status_line("!Can't convert Net/Node address");
  70.     return(0);
  71.     }
  72. if (!nodefind(opusnet,opusnode))        /* if we can't find the node */
  73.     return(0);                /* go away now               */
  74. status_line ("*Processing node %d/%d -- %s",opusnet,opusnode,nodedes.name);
  75. if (!CARRIER)                    /* if no carrier yet,        */
  76.    {
  77.    if (autobaud)
  78.       set_baud (ctl.max_baud, 1);   /* Set to our highest baud rate */
  79.    else
  80.        set_baud(nodedes.rate,1);        /* set baud to nodelist baud */
  81.    }
  82. return(1);                    /* return success to caller  */
  83. }
  84.  
  85. /*---------------------------------------------------------------------------*/
  86. /* NODEFIND                                                                  */
  87. /* Find nodelist entry for use by other routines (password, nodeproc)        */
  88. /* If found, result will be in "nodedes".                                    */
  89. /*---------------------------------------------------------------------------*/
  90.  
  91. nodefind(opusnet,opusnode)
  92. int opusnet,opusnode;                /* net and node              */
  93. {
  94. register struct _ndi *nodeidx;            /* index file                */
  95. int foundnet = 0;                /* 'found the net' flag      */
  96. int found = 0;                    /* 'found the node' flag     */
  97. long nodeoff = 0L;                /* offset into nodelist.sys  */
  98. char temp[80];                    /* where we build filenames  */
  99. int i;
  100. FILE *stream;
  101. struct stat f;
  102.  
  103. if (node_index == NULL)
  104.     {
  105.     temp[0] = '\0';                /* "null-terminated string"  */
  106.     strcpy(temp,ctl.net_info);        /* take nodelist path        */
  107.     strcat(temp,"NODELIST.IDX");        /* add in the file name      */
  108.     if ((stream = fopen(temp,"rb")) == NULL)/* OK, let's open the file   */
  109.         {
  110.         status_line("!Unable to open Nodelist.Idx file");
  111.         return(0);            /* no file, no work to do    */
  112.         }
  113.     fstat (fileno(stream),&f);        /* get file statistics       */
  114.     i = f.st_size;                /* size of index file,       */
  115.     idx_size = i / sizeof(struct _ndi);    /* number of index entries   */
  116.     node_index = (struct _ndi *)malloc(i);
  117.     if (node_index == NULL)
  118.         {
  119.         status_line("!Unable to allocate memory for Nodelist Index");
  120.         fclose(stream);
  121.         return(0);
  122.         }
  123.     if (fread(node_index,i,1,stream) != 1)
  124.         {
  125.         status_line("!Failed to read nodelist index into memory");
  126.         return(0);
  127.         }
  128.     fclose(stream);
  129.     }
  130. nodeidx = node_index;
  131. for (i = 1; i <= idx_size; i++)
  132.     {
  133.     if (nodeidx->net == opusnet)        /* if a match on net,        */
  134.         {
  135.         foundnet = 1;            /* say we found the net      */
  136.         if (((opusnode == 0) && (nodeidx->node <= 0))
  137.         || (nodeidx->node == opusnode))    /* see if we found the node  */
  138.             {
  139.               found = 1;        /* say we found it           */
  140.             break;            /* get out                   */
  141.             }
  142.         }
  143.     else
  144.         if (foundnet)            /* already past the net?     */
  145.             break;            /* Yes, we failed...         */
  146.     nodeoff += sizeof(nodedes);        /* keep track of .SYS offset */
  147.     ++nodeidx;                /* bump to next index pointer*/
  148.     }
  149.  
  150. if (!found)
  151.     {
  152.     status_line("!Couldn't find Net/Node: %d/%d",opusnet,opusnode);
  153.     return(0);
  154.     }
  155.  
  156. strcpy(temp,ctl.net_info);            /* take nodelist path        */
  157. strcat(temp,"NODELIST.SYS");            /* add in the file name      */
  158. if ((stream = fopen(temp,"rb")) == NULL)    /* OK, let's open the file   */
  159.     {
  160.     status_line("!Unable to open Nodelist.Sys file");
  161.     return(0);
  162.     }
  163.  
  164. if (fseek(stream,nodeoff,SEEK_SET))        /* try to point at record    */
  165.     {
  166.     status_line("!Unable to position to node record in Nodelist.Sys");
  167.     fclose(stream);
  168.     return(0);
  169.     }
  170.  
  171. if (!fread(&nodedes,sizeof(nodedes),1,stream))
  172.     {
  173.     status_line("!Not able to read node record from Nodelist.Sys");
  174.     fclose(stream);
  175.     return(0);
  176.     }
  177. fclose(stream);
  178.  
  179. return(1);
  180. }
  181.